/*-------------------------------------------------------------------------
 * CLR版本:     4.0.30319.42000
 * 创建人:      song
 * 创建时间：   2024/4/9 17:56:20
 * 功 能：      枚举绘制器
 *-------------------------------------------------------------------------*/

#if UNITY_EDITOR
namespace SCore.Editor.SShaderDraw
{
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;

    public class SEnumProp : SPropSuperBase<int>
    {
        private string[] enumNameArr; // 枚举名数组
        private int selectIndex; // 保存枚举选中的

        public override void Draw(float space, float BtnSize = 40)
        {
            if (this.props.ContainsKey(this.name))
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Space(space);
                EditorGUILayout.LabelField(base.lable, SPropBase.fontStyle);
                int selectIndex = getValue();
                setValue(EditorGUILayout.Popup(selectIndex, enumNameArr));
                base.DrawResetBtn(BtnSize, () => { ResetDefaultValue(); });
                GUILayout.EndHorizontal();
            }
        }


        protected override int getValue()
        {
            return (int)this.props[name].floatValue;
        }

        protected override void ResetDefaultValue()
        {
            this.props[name].floatValue = defaultValue;
        }

        protected override void setValue(int value)
        {
            this.props[name].floatValue = value;
        }

        public SEnumProp(string name, GUIContent lable, MaterialEditor materialEditor,
            Dictionary<string, MaterialProperty> props, int defaultValue, string[] enumNameArr) :
            base(name, lable, materialEditor, props, defaultValue)
        {
            this.selectIndex = defaultValue;
            this.enumNameArr = enumNameArr;
        }
    }
}
#endif